package com.qf.service.impl;

import com.qf.mapper.UserMapper;
import com.qf.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
       //校验用户名
        User user = userMapper.findByUsername(username);
        if (user ==null){
            System.out.println("密码或者用户名错误");
            return null;
        }
        //授权
        List<GrantedAuthority> list = new ArrayList<>();//权限的集合
        return new org.springframework.security.core.userdetails.User(username,user.getPassword(),list);
    }
}
